package map04;

import java.util.HashMap;
import java.util.Map;

public class HashMapDemo01 {
    public static void main(String[] args) {
        HashMap<String, Student> hm = new HashMap<>();
        Student s1 = new Student("01", "张三");
        Student s2 = new Student("05", "李四");
        Student s3 = new Student("07", "王五");
        hm.put(s1.getSno(), s1);
        hm.put(s2.getSno(), s2);
        hm.put(s3.getSno(), s3);

        System.out.println(hm);
        System.out.println("------------------------");
        //1.利用keySet方式遍历
        for (String key : hm.keySet()) {
            //System.out.println(key + " " + hm.get(key));
            System.out.println(key + " " + hm.get(key).getName());
        }

        System.out.println("------------------------");
        //2.利用entrySet方式遍历
        for (Map.Entry<String, Student> me : hm.entrySet()) {
            System.out.println(me.getKey() + " " + me.getValue());
        }
    }
}
